<template>
	<view>
		<!-- 	<ren-dropdown-filter :filterData='filterData' :border="false" :defaultIndex='defaultIndex' @onSelected='change'
			class="u-skeleton-rect">
		</ren-dropdown-filter> -->
		<view class="hread">
			<u-search placeholder="请输入查找的商家名称" v-model="keyword" @search="search" @change="search" :showAction="false"></u-search>
		</view>
		<view class="haedlist">
			<view class="margin-lr-sm margin-top-16" v-if="dataList.length">
				<view class="flex justify-between radius bg padding-sm margin-top-16" @click="shop(item.userId)"
					v-for="(item,index) in dataList" :key='index'>
					<image :src="item.shopImg?item.shopImg: '../../../static/logo.png'"
						style="width: 200rpx;height: 200rpx;border-radius: 10rpx;" mode="aspectFill"></image>
					<view class="flex-sub margin-left text-white flex flex-direction justify-between">
						<view class="flex align-center">
							<image src="../../../static/images/qi.png" style="width: 80rpx;height: 40rpx;"></image>
							<view class="margin-right-xs u-line-1"
								style="display: inline-block;margin-left: 10rpx;width: 340rpx;">
								{{item.shopName}}
							</view>
						</view>
						<view class="margin-tb-xs">营业时间：工作日{{item.startTime}}—{{item.endTime}}</view>
						<view>商家品类：{{item.shopType}}</view>
					</view>
				</view>
			</view>
		</view>

		<empty v-if="!dataList.length"></empty>
	</view>
</template>

<script>
	import empty from '@/components/empty.vue'
	export default {
		components: {
			empty
		},
		data() {
			return {
				page: 1,
				limit: 10,
				dataList: [],
				isVip: false,
				myId: '',
				city: '',
				defaultIndex: [0, 0, 0],
				filterData: [
					[{
							label: '智能优选',
							value: '',
						},
						{
							label: '距离优先',
							value: 3,
						},
						{
							label: '人气优先',
							value: 2,
						},
						{
							label: '同城',
							value: 1,
						}
					],
					[{
							label: '销量',
							value: '',
						},
						{
							label: '从高到低',
							value: 'desc',
						},
						{
							label: '从低到高',
							value: 'asc',
						}
					],
					[{
							label: '价格',
							value: '',
						},
						{
							label: '从高到低',
							value: 'desc',
						},
						{
							label: '从低到高',
							value: 'asc',
						}
					],
				],
				value1: '',
				value2: '',
				value3: '',
				keyword: '',

			}
		},
		onLoad() {
			this.isVip = uni.getStorageSync('isVIP') ? uni.getStorageSync('isVIP') : false
			this.myId = uni.getStorageSync('userId')
			this.city = uni.getStorageSync('city')
			this.getDataList()
		},
		methods: {
			search(){
				this.getDataList()
			},
			// 跳转店铺
			shop(userId) {
				uni.navigateTo({
					url: '/pages/index/game/shop?shopUserId=' + userId
				})
			},
			// 筛选
			change(e) {

				this.value1 = e[0][0].value
				this.value2 = e[1][0].value
				this.value3 = e[2][0].value
				this.getDataList()
				// this.mescroll.resetUpScroll()
			},
			getDataList() {
				this.$Request.get("/app/userCertification/queryCertification", {
					page: this.page,
					limit: this.limit,
					// condition: this.value1, //智能优选
					// salesNum: this.value2, //不限男女
					// by: this.value3, //价格
					name:this.keyword,
					classify: 2,
					isRecommend: 1,
					// city: this.city,
					latitude: uni.getStorageSync('latitude'),
					longitude: uni.getStorageSync('longitude'),
					userId: uni.getStorageSync('userId') ? uni.getStorageSync('userId') : '',
				}).then(res => {
					if (res.code == 0) {
						if (this.page == 1) {
							for (let i = 0; i < res.data.list.length; i++) {
								if (res.data.list[i].distance) {
									res.data.list[i].distance = (res.data.list[i].distance / 1000).toFixed(1)
								}
								if (res.data.list[i].gameName) {
									res.data.list[i].gameName = res.data.list[i].gameName.split(",");
								}
							}
							this.dataList = res.data.list
						} else {
							for (let i = 0; i < res.data.list.length; i++) {
								if (res.data.list[i].distance) {
									res.data.list[i].distance = (res.data.list[i].distance / 1000).toFixed(1)
								}
								if (res.data.list[i].gameName) {
									res.data.list[i].gameName = res.data.list[i].gameName.split(",");
								}
							}
							this.dataList = [...this.dataList, ...res.data.list]
						}
					}
					uni.stopPullDownRefresh();
				});
			},

			// 跳转订单
			goOrder(e) {
				let token = uni.getStorageSync('token')
				if (token) {
					uni.navigateTo({
						url: '/pages/index/game/order?id=' + e.id
					});
				} else {
					uni.navigateTo({
						url: '/pages/public/login'
					});
				}
			},
		},
		onReachBottom: function() {
			this.page = this.page + 1;
			this.getDataList();
		},
		onPullDownRefresh: function() {
			this.page = 1;
			this.getDataList();
		},
	}
</script>

<style>
	page {
		background-color: #f7f7f7;
	}

	.bg {
		background: #ffffff;
	}

	.hread {
		background: #FFFFFF;
		padding: 30rpx 20rpx;
		position: fixed;
		/* #ifdef H5 */
		top: 85rpx;
		/* #endif */
		/* #ifndef H5 */
		top: 0;
		/* #endif */
		left: 0;
		right: 0;
		z-index: 999;
	}
	.haedlist{
		margin-top: 140rpx;
	}
</style>